package com.ext.aic.apis.agent;

import android.content.Context;

import androidx.lifecycle.LifecycleOwner;

import com.ext.aic.apis.ApiDefine;
import com.ext.aic.apis.ApiPaths;
import com.ext.aic.apis.RequestResponse;
import com.ext.aic.beans.params.InsertUpdateAIParams;
import com.ext.aic.beans.response.InsertUpdateAIResponse;
import com.ext.aic.beans.response.Response;
import com.ext.aic.utils.ToastyUtils;
import com.eyinfo.android_pure_utils.utils.JsonUtils;
import com.hjq.http.EasyHttp;
import com.hjq.http.body.JsonRequestBody;

public class InsertUpdateAIRequest {

    protected void onInsertUpdateAISuccess(InsertUpdateAIResponse response) {

    }

    public void request(Context context, LifecycleOwner lifecycleOwner, InsertUpdateAIParams params) {
        EasyHttp.post(lifecycleOwner)
                .api(new ApiDefine(ApiPaths.insertUpdateAI))
                .body(new JsonRequestBody(JsonUtils.toJson(params)))
                .request(new RequestResponse<Response<InsertUpdateAIResponse>>(context, false) {

                    @Override
                    protected void onSuccess(Response<InsertUpdateAIResponse> response) {
                        if (response == null) {
                            return;
                        }
                        if (response.getCode() == 200) {
                            onInsertUpdateAISuccess(response.getData());
                        } else {
                            ToastyUtils.getInstance().show(response.getMessage());
                        }
                    }
                });
    }
}
